//
//  CCSClient.h
//  ivcs_ios_demo
//
//  Created by zealcomm user on 2020/10/22.
//  Copyright © 2020 zealcomm user. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZcoModelCcsMessage.h"
#import "CallBackObject.h"
#import "Constant.h"
#import "ZcoModelMember.h"
#import "ZcoModelUserInfo.h"
#import "ZcoModelCMD.h"
#import "ZcoModelFormBrief.h"
#import <SocketIO/SocketIO-Swift.h>
#import "ZcoModelLinkInfo.h"
#import "IRTCSDK.h"
@class ZcoModelConfirmData;
@class ZcoModelCMD;

@protocol IvcsBaseDelegate;

@protocol CCSClientDelegate <NSObject>

@optional

/// ccs socketIo相关的错误回调
/// @param code 错误code
/// @param message message
-(void)ccsErrorWithCode:(IVCSSDKErrorCode)code andMessage:(NSString *_Nullable)message;

/// 呼叫坐席的进度回调
/// @param progress 进度的状态信息
-(void)onInvitationProgress:(NSDictionary *_Nonnull)progress;

/// 用户被drop
/// @param message 原因信息
-(void)onDrop:(NSDictionary *_Nonnull)message;

/// 用户加入session
/// @param personInfo 用户信息
-(void)onJoinSession:(NSDictionary *_Nonnull)personInfo;

/// 用户离开session
/// @param personInfo 用户信息
-(void)onQuitSession:(NSDictionary *_Nonnull)personInfo;

/// 坐席音视频准备就绪
-(void)agentVideoReadyToTalk;

/// 正在转接其他坐席
-(void)onHoldOn;

@end

@protocol CCSClientMessageDelegate <NSObject>

-(void)onCcsServerMessage:(NSArray * _Nonnull) data;

@end


//@import SocketIO;
NS_ASSUME_NONNULL_BEGIN

@interface CCSClient : NSObject

declareSingleInstance()

@property (nonatomic,weak) NSObject<IvcsBaseDelegate> *ivcsSDKDelegate;

@property (nonatomic,weak) id<CCSClientDelegate>delegate;

@property (nonatomic,strong) NSObject<CCSClientMessageDelegate> *messageDelegate;

@property(strong , nonatomic) IRTCSDK *irtcSDK;

/// socektIOClient
@property(strong,nonatomic)SocketIOClient *socket;

//session clientId
@property(nonatomic,copy)NSString *clientId;

/// sessionId
@property(nonatomic,copy)NSString *sessionId;

/// session room Token
@property(strong,nonatomic)NSString *roomtoken;

/// session participants list
@property(strong,nonatomic)NSMutableArray<ZcoModelMember *> *userList;

/// 登录用户的用户信息
@property(strong , nonatomic)ZcoModelUserInfo *userInfo;

/// socketIo access token
@property(nonatomic,copy)NSString *accessToken;

@property(nonatomic , copy) NSString *baseUrl;

/// connect ccs socketio
/// @param ccsUrl url
/// @param token access token
/// @param complete callback
-(void)connectWithUrl:(nonnull NSString *)ccsUrl andToken:(nonnull NSString *)token complete:(completeBlock)complete;


/// 发起视频呼叫（发起后自动加入会话）
/// @param requestParameter 呼叫参数
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)requestSession:(nonnull NSDictionary *)requestParameter
        onSuccess:(void (^)(NSDictionary *result))onSuccess
        onFailure:(void (^)(NSError *error))onFailure;

/// 加入会话
/// @param invitationId 响铃时获得的邀请 id
/// @param sessionId 响铃时获得的 sessionId
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)joinSession:(nonnull NSString *)invitationId  withSessionId:(NSString *)sessionId onSuccess:(void (^)(NSDictionary *result))onSuccess
        onFailure:(void (^)(NSError *error))onFailure;

/// ccsclient is valid
/// @param client ccsClient object
+(void)validateCcsClient:(CCSClient *)client
                 onSuccess:(void (^)(void))onSuccess
                 onFailure:(void (^)(NSError *error))onFailure;

/// 告知对方，本地音视频已准备完成
/// @param roles 发送给的角色 默认是'agents'
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)readyToTalkToRoles:(NSString *)roles onSuccess:(void (^)(void))onSuccess onFailure:(void (^)(NSError * _Nonnull))onFailure;

/// 退出会话
/// @param parameter 默认为空
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)quitSession:(_Nullable id)parameter
                onSuccess:(void (^)(void))onSuccess
                onFailure:(void (^)(NSError *error))onFailure;



/// 分享url资源文件给对方
/// @param type 资源类型 ['doc','pic','video','aduio','page','paper']
/// @param url 资源地址
/// @param name 资源名字
/// @param roles 发送给角色 agents/customers
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)shareResourceWithType:(NSString *)type
                 resourceUrl:(NSString *)url
                 resourceName:(NSString *)name
                 toRoles:(NSString *)roles
                 onSuccess:(void (^)(void))onSuccess
                 onFailure:(void (^)(NSError *error))onFailure;




/// 分享资源文件
/// @param type 文件类型  ['doc','pic','video','aduio','page','paper']
/// @param uploadUrl 上传的url
/// @param fileData fileData
/// @param fileName 文件名
/// @param mimeType 文件类型
/// @param roles 发送给对方的角色 默认是agents
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)shareResourceWithType:(NSString *)type
            uploadUrl:(NSString *)uploadUrl
            fileData:(NSData *)fileData
            fileName:(NSString *)fileName
            mimeType:(NSString *)mimeType
            toRoles:(NSString *)roles
            onSuccess:(void (^)(void))onSuccess
            onFailure:(void (^)(NSError *error))onFailure;


/// 发送自定义消息
/// @param data 消息内容
/// @param roles 发送给角色 agents/customers
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)sendCustomMessage:(NSString *)data
        toRoles:(NSString *)roles
        onSuccess:(void (^)(void))onSuccess
        onFailure:(void (^)(NSError *error))onFailure;


/// 发送文本消息
/// @param data 消息内容
/// @param roles 发送给角色 agents/customers
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)sendTextMessage:(NSString *)data
        toRoles:(NSString *)roles
        onSuccess:(void (^)(void))onSuccess
        onFailure:(void (^)(NSError *error))onFailure;


/// 发送消息确认
/// @param data 消息确认的信息体
/// @param roles 发送给的角色 默认是“agents”
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)sendMessageConfirmation:(ZcoModelConfirmData *)data
        toRoles:(NSString *)roles
        onSuccess:(void (^)(void))onSuccess
        onFailure:(void (^)(NSError *error))onFailure;

/// 发送截屏消息
/// @param data 信息体
/// @param roles 发送给的角色 默认是“agents”
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)sendSnapshotMessage:(NSDictionary *)data toRoles:(NSString * __nullable)roles onSuccess:(void (^ __nullable)(void))onSuccess onFailure:(void (^ __nullable)(NSError * _Nonnull error))onFailure;


/// 指令取消消息
/// @param data 信息体
/// @param roles 发送给的角色
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)sendCmdCancleMessage:(ZcoModelCMD *)data toRoles:(NSString * __nullable)roles onSuccess:(void (^ __nullable)(void))onSuccess onFailure:(void (^ __nullable)(NSError * _Nonnull error))onFailure;

/// 发送表单消息
/// @param data 消息内容
/// @param roles 发送给角色 agents/customers
/// @param onSuccess 成功
/// @param onFailure 失败
-(void)sendFormData:(NSDictionary *)data
        toRoles:(NSString *)roles
        onSuccess:(void (^)(void))onSuccess
        onFailure:(void (^)(NSError *error))onFailure;
/// 转接或者三方
/// @param agent 转接人ID
/// @param bizSceneName 转接人机构
/// @param type  类型 表示转接或者三方
-(void)inviteWithAgent:(NSString *)agent andBizSceneName:(NSString *)bizSceneName witCustomer:(NSDictionary *)type onSuccess:(void (^)(void))onSuccess onFailure:(void (^)(NSError * _Nonnull error))onFailure;

-(void)invite:(NSString *)invitationId withBizScreen:(NSString *)screen andCustomer:(NSDictionary *)customer  onSuccess:(void (^)(NSDictionary * _Nonnull))onSuccess onFailure:(void (^)(NSError * _Nonnull))onFailure;


/// 发送指令
/// @param cmd 指令
/// @param roles 发送给角色 agents/customers
/// @param onSuccess 成功
/// @param onFailure 失败
/// 
- (void)sendPeerCMD:(ZcoModelCMD *)cmd to:(NSString *)roles onSuccess:(void (^__nullable)(void))onSuccess onFailure:(void (^__nullable)(NSError * _Nonnull error))onFailure;

/// 响应指令
/// @param cmd 指令
/// @param roles 发送给角色 agents/customers
/// @param onSuccess 成功
/// @param onFailure 失败
- (void)sendPeerResponse:(ZcoModelCMD *)cmd to:(NSString *)roles onSuccess:(void (^)(void))onSuccess onFailure:(void (^)(NSError * _Nonnull error))onFailure;
/// 状态指令
/// @param cmd 指令
/// @param roles 发送给角色
/// @param onSuccess 成功
/// @param onFailure 失败
- (void)sendPeerState:(NSDictionary *)cmd to:(NSString *)roles onSuccess:(void (^)(void))onSuccess onFailure:(void (^)(NSError * _Nonnull error))onFailure;

/// 发送一般session消息
/// @param cmd 指令
/// @param roles 发送给角色 agents/customers
/// @param onSuccess 成功
/// @param onFailure 失败
///
- (void)sendNormalSession:(NSDictionary *)cmd with:(NSString *)type to:(NSString *)roles onSuccess:(void (^__nullable)(void))onSuccess onFailure:(void (^__nullable)(NSError * _Nonnull error))onFailure;

/// 发送手写签名消息(这里使用的是 fabric3.4 方案
- (void)sendHandWritingMessage:(NSString *)msg to:(NSString *)roles;

/// 只能在 request-session 后调用，否则会导致连接中断
-(void)refreshTicket;
#pragma mark 强拆
-(void)dropMessageWith:(NSDictionary *)dic;

-(void)screenShare:(NSDictionary *)dic;
@end

NS_ASSUME_NONNULL_END
